~ chicken-core (chicken-5) /manual/Module (chicken keyword)
Trap1[[tags: manual]]
2[[toc:]]
3
4== Module (chicken keyword)
5
6Keywords are written like symbols, but prefixed with {{#:}}. They
7evaluate to themselves. While they behave a lot like symbols in that
8they are interned when read and can be compared in constant time with
9{{eq?}}, they are a distinct type. In particular, they have no plist,
10they cannot be bound or assigned to and aren't {{eq?}} to a symbol
11with the same spelling. Procedures can use keywords to accept
12optional named parameters in addition to normal required parameters.
13
14The parameter {{keyword-style}} and the compiler/interpreter option
15{{-keyword-style}} can be used to allow an additional keyword syntax,
16either compatible to Common LISP, or to DSSSL. As long as this
17parameter is set to {{#:suffix}}, CHICKEN conforms to
18[[http://srfi.schemers.org/srfi-88/srfi-88.html|SRFI-88]].
19
20There is also a {{srfi-88}} or {{(srfi 88)}} module which only
21includes the standard procedures from the SRFI document, without the
22CHICKEN extensions. {{(chicken keyword)}} offers the complete set of
23procedures, both CHICKEN-specific and standard SRFI-88.
24
25==== get-keyword
26
27<procedure>(get-keyword KEYWORD ARGLIST [THUNK])</procedure>
28
29Returns the argument from {{ARGLIST}} specified under the keyword
30{{KEYWORD}}. If the keyword is not found, then the zero-argument
31procedure {{THUNK}} is invoked and the result value is returned. If
32{{THUNK}} is not given, {{#f}} is returned.
33
34<enscript highlight=scheme>
35(define (increase x . args)
36 (+ x (get-keyword #:amount args (lambda () 1))) )
37(increase 123) ==> 124
38(increase 123 #:amount 10) ==> 133
39</enscript>
40
41==== keyword?
42
43<procedure>(keyword? X)</procedure>
44
45Returns {{#t}} if {{X}} is a keyword, or {{#f}} otherwise.
46
47
48==== keyword->string
49
50<procedure>(keyword->string KEYWORD)</procedure>
51
52Transforms {{KEYWORD}} into a string.
53
54
55==== string->keyword
56
57<procedure>(string->keyword STRING)</procedure>
58
59Returns a keyword with the name {{STRING}}.
60
61
62---
63Previous: [[Module (chicken irregex)]]
64
65Next: [[Module (chicken load)]]